$(function(){
	$(".datagrid-pager.pagination.ensureTag").append("<div class='ensureDiv'><a class='easyui-linkbutton l-btn l-btn-small ensure'>确定</a><a class='easyui-linkbutton l-btn l-btn-small'>取消</a></div>")
    $(document).on("click",".bindstore",function(){
        var index = layer.open({
            type: 2,
            title: '门店列表管理',
            area: ['800px', '560px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/erpcustomer'
        });
        this.layerIndex = index;
        var clientId=$(this).parents("tr").children("td[field='clientId']").text()
        var clientName=$(this).parents("tr").children("td[field='clientName']").text()
        var orgId=$(this).parents("tr").children("td[field='orgId']").text()
        var orgCode=$(this).parents("tr").children("td[field='orgCode']").text()
        var orgName=$(this).parents("tr").children("td[field='orgName']").text()
        var bindstoreData=
            {clientId:clientId,
            clientName:clientName,
            //orgId:orgId,
           // orgCode:orgCode,
            //orgName:orgName
           }
        console.log(bindstoreData)
        // var ajax = new $ax(Feng.ctxPath +'url', function (data) {
        //     Feng.success("请求成功!");
        // }, function (data) {
        //     Feng.error("请求失败!" + data.responseJSON.message + "!");
        // });
        // ajax.set(bindstoreData);
        // ajax.start();
    })
    $(document).on("click","input[name=storecheck]",function(){
        if($(this).attr("checked")=="checked"){
            $(this).removeAttr("checked");
        }else{
            $(this).attr("checked","checked");
        }
    })
    $(document).on("click",".ensure",function(){
        var checkNum=$("input[checked=checked]").length;
        var objErpcustomerArr=[];
        for(var i=0;i<checkNum;i++){
            var orgId=$($("input[checked=checked]")[i]).parents("td").siblings("td[field=orgId]").text()
            var orgCode=$($("input[checked=checked]")[i]).parents("td").siblings("td[field=orgCode]").text()
            var orgName=$($("input[checked=checked]")[i]).parents("td").siblings("td[field=orgName]").text()
            var orgShortName=$($("input[checked=checked]")[i]).parents("td").siblings("td[field=orgShortName]").text()
            var activity=$($("input[checked=checked]")[i]).parents("td").siblings("td[field=activity]").text()
            var objErpcustomer={
                orgId:orgId,
                orgCode:orgCode,
                orgName:orgName,
                orgShortName: orgShortName,
                activity:activity
            }
            objErpcustomerArr.push(objErpcustomer)
        }
        console.log(objErpcustomerArr)
        // var ajax = new $ax(Feng.ctxPath +'url', function (data) {
        //     Feng.success("请求成功!");
        // }, function (data) {
        //     Feng.error("请求失败!" + data.responseJSON.message + "!");
        // });
        // ajax.set(bindstoreData);
        // ajax.start();
    })
    $(document).on("click",".search-relative",function(){
       console.log($(".datagrid-row-selected").children("td"))
       var clientId=$(".datagrid-row-selected").children("td[field=clientId]").text()
       var clientName=$(".datagrid-row-selected").children("td[field=clientName]").text()
       var orgId=$(".datagrid-row-selected").children("td[orgId]").text()
       var orgCode=$(".datagrid-row-selected").children("td[orgCode]").text()
       var orgName=$(".datagrid-row-selected").children("td[field=orgName]").text()
       var relativeObj={
            clientId:clientId,
            clientName:clientName,
            orgId:orgId,
            orgCode:orgCode,
            orgName:orgName,
       }
       console.log(relativeObj)
        var index = layer.open({
            type: 2,
            title: '门店列表管理',
            area: ['800px', '560px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/erpcustomer'
        });
        this.layerIndex = index;
    })
    $(document).on("click",".search-relative",function(){
        console.log($(".datagrid-row-selected").children("td"))
        var clientId=$(".datagrid-row-selected").children("td[field=clientId]").text()
        var clientName=$(".datagrid-row-selected").children("td[field=clientName]").text()
        var orgId=$(".datagrid-row-selected").children("td[field=orgId]").text()
        var orgCode=$(".datagrid-row-selected").children("td[field=orgCode]").text()
        var orgName=$(".datagrid-row-selected").children("td[field=orgName]").text()
        var relativeObj={
             clientId:clientId,
             clientName:clientName,
             orgId:orgId,
             orgCode:orgCode,
             orgName:orgName,
        }
        console.log(relativeObj)
         var index = layer.open({
             type: 2,
             title: '门店列表管理',
             area: ['800px', '560px'], //宽高
             fix: false, //不固定
             maxmin: true,
             content: Feng.ctxPath + '/erpcustomer'
         });
         this.layerIndex = index;
     })

     $(document).on("click",".search-relative-pro",function(){
        console.log($(".datagrid-row-selected").children("td"))
        var clientId=$(".datagrid-row-selected").children("td[field=clientId]").text()
        var clientName=$(".datagrid-row-selected").children("td[field=clientName]").text()
        var orgId=$(".datagrid-row-selected").children("td[field=productId]").text()
        var orgCode=$(".datagrid-row-selected").children("td[field=productCode]").text()
        var orgName=$(".datagrid-row-selected").children("td[field=productName]").text()
        var relativeObj={
             clientId:clientId,
             clientName:clientName,
             productId:orgId,
             productCode:orgCode,
             productName:orgName,
        }
        console.log(relativeObj)
        //  var index = layer.open({
        //      type: 2,
        //      title: '门店列表管理',
        //      area: ['800px', '560px'], //宽高
        //      fix: false, //不固定
        //      maxmin: true,
        //      content: Feng.ctxPath + '/erpcustomer'
        //  });
        //  this.layerIndex = index;
     })
})